1
|
|
|
import { |
2
|
|
|
Body, |
3
|
|
|
Controller, |
4
|
|
|
Inject, |
5
|
|
|
BadRequestException, |
6
|
|
|
UseGuards, |
7
|
|
|
Put, |
8
|
|
|
Param |
9
|
|
|
} from '@nestjs/common'; |
10
|
|
|
import { AuthGuard } from '@nestjs/passport'; |
11
|
|
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger'; |
12
|
|
|
import { ICommandBus } from 'src/Application/ICommandBus'; |
13
|
|
|
import { UpdateShootingCommand } from 'src/Application/School/Command/Shooting/UpdateShootingCommand'; |
14
|
|
|
import { UserRole } from 'src/Domain/User/User.entity'; |
15
|
|
|
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO'; |
16
|
|
|
import { Roles } from 'src/Infrastructure/User/Decorator/Roles'; |
17
|
|
|
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard'; |
18
|
|
|
import { ShootingDTO } from '../../DTO/ShootingDTO'; |
19
|
|
|
|
20
|
|
|
@Controller('schools/:schoolId/shootings') |
21
|
|
|
@ApiTags('School shooting') |
22
|
|
|
@ApiBearerAuth() |
23
|
|
|
@UseGuards(AuthGuard('bearer'), RolesGuard) |
24
|
|
|
export class UpdateShootingAction { |
25
|
|
|
constructor( |
26
|
|
|
@Inject('ICommandBus') |
27
|
|
|
private readonly commandBus: ICommandBus |
28
|
|
|
) { } |
29
|
|
|
|
30
|
|
|
@Put(':id') |
31
|
|
|
@Roles(UserRole.PHOTOGRAPHER) |
32
|
|
|
@ApiOperation({ summary: 'Update shooting' }) |
33
|
|
|
public async index(@Param() idDto: IdDTO, @Body() dto: ShootingDTO) { |
34
|
|
|
try { |
35
|
|
|
const { name, groupClosingDate, shootingDate, individualClosingDate, notice } = dto; |
36
|
|
|
const id = await this.commandBus.execute( |
37
|
|
|
new UpdateShootingCommand( |
38
|
|
|
idDto.id, |
39
|
|
|
name, |
40
|
|
|
new Date(shootingDate), |
41
|
|
|
new Date(groupClosingDate), |
42
|
|
|
new Date(individualClosingDate), |
43
|
|
|
notice |
44
|
|
|
) |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
return { id }; |
48
|
|
|
} catch (e) { |
49
|
|
|
throw new BadRequestException(e.message); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|